1 module unit_threaded.randomized; 2 3 public import unit_threaded.randomized.gen; 4 public import unit_threaded.randomized.random; 5 public import unit_threaded.randomized.benchmark; 6 7 /// 8 unittest { 9 import core.thread : Thread; 10 import core.time : seconds; 11 12 struct Foo { 13 void superSlowMethod(int a, Gen!(int, -10, 10) b) { 14 Thread.sleep(1.seconds / 250000); 15 doNotOptimizeAway(a); 16 } 17 } 18 19 Foo a; 20 21 auto del = delegate(int ai, Gen!(int, -10, 10) b) { 22 a.superSlowMethod(ai, b); 23 }; 24 25 benchmark!(del)(); 26 } 27 28 /// 29 unittest // test that the function parameter names are correct 30 { 31 import std..string : indexOf; 32 import std.experimental.logger; 33 34 class SingleLineLogger : Logger { 35 this() { 36 super(LogLevel.info); 37 } 38 39 override void writeLogMsg(ref LogEntry payload) @safe { 40 this.line = payload.msg; 41 } 42 43 string line; 44 } 45 46 auto oldLogger = stdThreadLocalLog; 47 auto newLogger = new SingleLineLogger(); 48 stdThreadLocalLog = newLogger; 49 scope (exit) 50 stdThreadLocalLog = oldLogger; 51 52 static int failingFun(int a, string b) { 53 throw new Exception("Hello"); 54 } 55 56 log(); 57 benchmark!failingFun(); 58 59 assert(newLogger.line.indexOf("'a'") != -1); 60 assert(newLogger.line.indexOf("'b'") != -1); 61 }